home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / mkversion / RCS / mkversion.c,v < prev    next >
Encoding:
Text File  |  1988-11-13  |  4.7 KB  |  252 lines

  1. head     1.4;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.4
  10. date     88.11.13.12.02.47;  author brent;  state Exp;
  11. branches ;
  12. next     1.3;
  13.  
  14. 1.3
  15. date     88.11.01.18.27.26;  author mlgray;  state Exp;
  16. branches ;
  17. next     1.2;
  18.  
  19. 1.2
  20. date     88.02.21.15.52.47;  author douglis;  state Exp;
  21. branches ;
  22. next     1.1;
  23.  
  24. 1.1
  25. date     87.08.13.14.05.40;  author andrew;  state Exp;
  26. branches ;
  27. next     ;
  28.  
  29.  
  30. desc
  31. @initial sprite version
  32. @
  33.  
  34.  
  35. 1.4
  36. log
  37. @Added exit(0)
  38. @
  39. text
  40. @/* 
  41.  * mkversion.c --
  42.  *
  43.  *    Output a string to be used as "version.h" describing the current
  44.  *    working directory and date/time.
  45.  *
  46.  * Copyright 1987 Regents of the University of California
  47.  * All rights reserved.
  48.  */
  49.  
  50. #ifndef lint
  51. static char rcsid[] = "$Header: /a/newcmds/mkversion/RCS/mkversion.c,v 1.3 88/11/01 18:27:26 mlgray Exp $ SPRITE (Berkeley)";
  52. #endif not lint
  53.  
  54. #include "stdio.h"
  55. #include "sys/param.h"
  56. #include "sys/time.h"
  57. #include "time.h"
  58. #include "option.h"
  59.  
  60. int printDir = 0;
  61. int printDate = 1;
  62. char *prog = NULL;
  63.  
  64. Option optionArray[] = {
  65.     {OPT_TRUE, "d",  (char *) &printDir,
  66.     "Print the current working directory (TRUE)"},
  67.     {OPT_FALSE, "t",  (char *) &printDate,
  68.     "Don't print the date/time-stamp (FALSE)"},
  69.     {OPT_STRING, "p",  (char *) &prog,
  70.     "Output program name STRING (following the directory, if applicable)"},
  71. };
  72. int numOptions = sizeof(optionArray) / sizeof(Option);
  73.  
  74. main(argc, argv)
  75.     int        argc;
  76.     char    *argv[];
  77. {
  78.     struct    timeval    curTime;
  79.     struct    timezone    local;
  80.     char     pathName[MAXPATHLEN];
  81.  
  82.     (void) Opt_Parse(argc, argv, optionArray, numOptions, OPT_ALLOW_CLUSTERING);
  83.  
  84.     printf("#define VERSION \"");
  85.     
  86.     if (printDir) {
  87.     if (getwd(pathName) == NULL) {
  88.         fprintf(stderr, "Error in getwd: '%s'\n", pathName);
  89.     } else {
  90.         printf("%s", pathName);
  91.     }
  92.     }
  93.     if (prog) {
  94.     if (printDir) {
  95.         printf("/");
  96.     }
  97.     printf("%s", prog);
  98.     }
  99.     if (printDir || prog) {
  100.     printf(" ");
  101.     }
  102.     if (printDate) {
  103.     char *date;
  104.     int numDateChars = 1;
  105.     extern char *asctime();
  106.  
  107.     gettimeofday(&curTime, &local);
  108.     date = asctime(localtime(&curTime.tv_sec));
  109.     /*
  110.      *  ctime format is ugly:
  111.      *  "Sat Aug 10 10:30:01 1987\n\0"
  112.      *   012345678901234567890123 4 5
  113.      *
  114.      * Make it look like Time_ToAscii by picking substrings.
  115.      * Get rid of the leading space in the date by checking for ' '
  116.      * and printing 1 or 2 chars, starting at the first non-blank.
  117.      */
  118.  
  119.     if (date[8] != ' ') {
  120.         numDateChars++;
  121.     }
  122.     printf("(%.*s %.3s %.2s %.8s)", numDateChars,
  123.          &date[10-numDateChars], &date[4], &date[22], &date[11]);
  124.     }
  125.     printf("\"\n");
  126.     exit(0);
  127. }
  128. @
  129.  
  130.  
  131. 1.3
  132. log
  133. @Ported to new C library.
  134. @
  135. text
  136. @d12 1
  137. a12 1
  138. static char rcsid[] = "$Header: /sprite/src/cmds/mkversion/RCS/mkversion.c,v 1.2 88/02/21 15:52:47 douglis Exp Locker: mlgray $ SPRITE (Berkeley)";
  139. d87 1
  140. @
  141.  
  142.  
  143. 1.2
  144. log
  145. @Changed format of date string.
  146. @
  147. text
  148. @d12 1
  149. a12 1
  150. static char rcsid[] = "$Header: mkversion.c,v 1.1 87/08/13 14:05:40 andrew Exp $ SPRITE (Berkeley)";
  151. d15 3
  152. a17 1
  153. #include "sprite.h"
  154. a18 2
  155. #include "io.h"
  156. #include "fs.h"
  157. d21 2
  158. a22 2
  159. Boolean printDir = FALSE;
  160. Boolean printDate = TRUE;
  161. d26 1
  162. a26 1
  163.     {OPT_TRUE, 'd', (Address) &printDir,
  164. d28 1
  165. a28 1
  166.     {OPT_FALSE, 't', (Address) &printDate,
  167. d30 1
  168. a30 1
  169.     {OPT_STRING, 'p', (Address) &prog,
  170. a34 2
  171. extern char *Fs_GetCwd();
  172.  
  173. d39 3
  174. a41 4
  175.     Time    curTime;
  176.     int        localOffset;
  177.     char    date[TIME_CVT_BUF_SIZE];
  178.     char pathName[FS_MAX_PATH_NAME_LENGTH];
  179. d43 1
  180. a43 1
  181.     (void) Opt_Parse(&argc, argv, numOptions, optionArray);
  182. d45 1
  183. a45 1
  184.     Io_Print("#define VERSION \"");
  185. d48 2
  186. a49 2
  187.     if (Fs_GetCwd(pathName) == NULL) {
  188.         Io_PrintStream(io_StdErr, "Error in Fs_GetCwd: '%s'\n", pathName);
  189. d51 1
  190. a51 1
  191.         Io_Print("%s", pathName);
  192. d56 1
  193. a56 1
  194.         Io_Print("/");
  195. d58 1
  196. a58 1
  197.     Io_Print("%s", prog);
  198. d61 1
  199. a61 1
  200.     Io_Print(" ");
  201. d64 3
  202. a66 1
  203.     Sys_GetTimeOfDay(&curTime, &localOffset, NULL);
  204. d68 2
  205. a70 19
  206.      * Sprite doesn't yet have a localtime function.  Since sprite
  207.      * routines are going to converge to unix names anyway,
  208.      * let's just call asctime(localtime) for now.  Grumble.
  209.      */
  210. #ifdef NO_UNIX
  211.     Time_ToAscii(curTime.seconds + (60 * (localOffset+60)), FALSE, date);
  212.     /*
  213.      *  "Sat, 10 Aug 87 10:30:01\0
  214.      *   01234567890123456789012 3
  215.      */
  216.     Io_Print("(%s)", &date[5]);
  217. #else NO_UNIX
  218.     {
  219.         char *date;
  220.         int numDateChars = 1;
  221.         extern char *asctime();
  222.  
  223.         date = asctime(localtime(&curTime.seconds));
  224.     /*
  225. d80 2
  226. a81 5
  227.         if (date[8] != ' ') {
  228.         numDateChars++;
  229.         }
  230.         Io_Print("(%.*s %.3s %.2s %.8s)", numDateChars,
  231.              &date[10-numDateChars], &date[4], &date[22], &date[11]);
  232. d83 2
  233. a84 1
  234. #endif NO_UNIX
  235. d86 1
  236. a86 1
  237.     Io_Print("\"\n");
  238. @
  239.  
  240.  
  241. 1.1
  242. log
  243. @Initial revision
  244. @
  245. text
  246. @d12 1
  247. a12 1
  248. static char rcsid[] = "$Header: mkversion.c,v 1.1 87/02/11 11:50:08 douglis Exp $ SPRITE (Berkeley)";
  249. d68 7
  250. d81 24
  251. @
  252.